package top.wshape1.shiziapi.common.constant;

/**
 * @author Wshape1
 * @version 1.0
 * @description
 * @since 2023-08-21
 */

public enum BizCodeEnum {

    UNKNOWN_ERROR(1, "未知错误"),
    SYSTEM_BUSY(2, "系统繁忙"),

    /*
    ========= Token =========
     */
    ILLEGAL_TOKEN(1101, "非法Token"),
    NOT_FOUND_TOKEN(1102, "没有携带Token"),
    EXPIRED_TOKEN(1103, "Token已过期"),

    /*
    ========= Login =========
     */
    EMAIL_PASSWORD_ERROR(1201, "邮箱或密码不正确"),
    EMAIL_EXIST_ERROR(1202, "邮箱已存在"),
    EMAIL_NOT_EXIST_ERROR(1203, "邮箱不存在"),
    EMAIL_SEND_ERROR(1203, "邮件发送失败"),
    EMAIL_SEND_TO_MORE_ERROR(1204, "邮件发送频繁"),
    OAUTH2_LOGIN_ERROR(1205, "第三方登录出错"),
    SAME_PASSWORD_ERROR(1206, "新旧密码相同"),
    /*
    ========= Valid =========
     */
    INVALID_DATA_ERROR(1301, "提交的数据异常"),
    INVALID_CODE_ERROR(1302, "验证码错误"),

    /*
    ========= Binding =======
     */
    LEAST_ONE_BINDING(1401, "最少需要留一个绑定关系"),
    EXIST_BINDING_ERROR(1402, "已存在该绑定关系"),

    /*
    ======== Project ======
     */
    PROJECT_NOT_EXIST_ERROR(1501, "项目不存在"),
    PROJECT_PERMISSION_ERROR(1502, "没有权限操作此项目"),

    /*
    ======= SSE =========
     */

    SSE_CONNECTING_ERROR(1601, "连接异常"),

    MORE_PLACE_LOGIN_ERROR(1602, "账号在多地登录"),

    /*
    ======= Mock ========
     */
    MOCK_PATH_EXIST_ERROR(1701, "Mock请求路径已存在"),

    MOCK_NOT_EXIST_ERROR(1702, "Mock配置不存在"),

    /*
    ========== Doc ===========
     */
    DOC_NOT_EXIST_ERROR(1801, "文档不存在"),
    DOC_VERSION_EXIST_ERROR(1802, "版本已存在"),
    DOC_NOT_IN_EDIT_ERROR(1803, "该文档当前未处于编辑状态，无法操作"),

    DOC_CONTENT_AUDIT_ERROR(1804, "内容审核不通过，涉嫌违规"),
    DOC_AI_SUMMARY_GENERATING(1805, "正在生成摘要中"),


    ;
    private final int code;

    private final String msg;

    BizCodeEnum(int code, String msg) {
        this.code = code;
        this.msg = msg;
    }

    public int code() {
        return code;
    }

    public String msg() {
        return msg;
    }

    public static BizCodeEnum valueOfByCode(int code) {
        for (BizCodeEnum bizCodeEnum : BizCodeEnum.values()) {
            if (bizCodeEnum.code == code) {
                return bizCodeEnum;
            }
        }
        return null;
    }

}
